﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;

namespace WF_Loadout_Editor
{
    public partial class MainForm : Form
    {
        ModForm modWindow;
        List<Warframe> warframes;
        List<Weapon> weapons;
        List<BaseMod> mods;
        List<Faction> factions;
        List<Polarity> WarframeButtonPolarities;
        List<Polarity> WeaponButtonPolarities;
        int iCurrentWarframe;
        int iCurrentWeapon;
        int iCurrentModSlot;

        public MainForm()
        {
            InitializeComponent();

            warframes = new List<Warframe>();
            weapons = new List<Weapon>();
            mods = new List<BaseMod>();
            factions = new List<Faction>();
            WarframeButtonPolarities = new List<Polarity>();
            WeaponButtonPolarities = new List<Polarity>();
            modWindow = null;
            iCurrentWarframe =
                iCurrentWeapon =
                iCurrentModSlot = 0;
            
            // 13 warframes
            // 53 weapons
            // 135 total mods(87 mods, 48 ability mods)
            // import warframes, guns, enemies
            // TODO: Import Everything
            ImportWarframes();
            ImportAllWeapons();
            ImportEnemies();

            // Add empty polarities
            for (int i = 0; i < 10; ++i)
            {
                if (i < 8)
                    WeaponButtonPolarities.Add(new Polarity(5, i));

                WarframeButtonPolarities.Add(new Polarity(5, i));
            }

            // set combo boxes and tabs
            WarframeCB.SelectedIndex = 0;
            WeaponCB.SelectedIndex = 0;
            FactionTC.SelectedIndex = 0;
        }

        public void ImportEnemy(XElement root, string part, List<Part> parts)
        {
            // import temp variables
            XElement xNormal;
            XElement xAP;
            XElement xElectric;
            XElement xFire;
            XElement xFrost;

            XElement xpart = root.Element(part);
            xNormal = xpart.Element("Normal");
            xAP = xpart.Element("AP");
            xElectric = xpart.Element("Electric");
            xFire = xpart.Element("Fire");
            xFrost = xpart.Element("Frost");
            Part tempPart = new Part((float)Convert.ToDouble(xNormal.Value),
                                     (float)Convert.ToDouble(xAP.Value),
                                     (float)Convert.ToDouble(xElectric.Value),
                                     (float)Convert.ToDouble(xFire.Value),
                                     (float)Convert.ToDouble(xFrost.Value));
            parts.Add(tempPart);
        }

        public void ImportGrineer(XElement root, List<Part> parts, List<Enemy> enemies)
        {
            Enemy tempEnemy;

            XElement xtemp = root.Element("Grineer");
            // light armor
            XElement xEnemy = xtemp.Element("LightArmor");
            ImportEnemy(xEnemy, "Body", parts);
            ImportEnemy(xEnemy, "Head", parts);
            tempEnemy = new Enemy("Light Armor", parts);
            enemies.Add(tempEnemy);
            parts.Clear();

            // medium armor
            xEnemy = xtemp.Element("MediumArmor");
            ImportEnemy(xEnemy, "Body", parts);
            ImportEnemy(xEnemy, "Head", parts);
            tempEnemy = new Enemy("Medium Armor", parts);
            enemies.Add(tempEnemy);
            parts.Clear();

            // heavy armor
            xEnemy = xtemp.Element("HeavyArmor");
            ImportEnemy(xEnemy, "Body", parts);
            ImportEnemy(xEnemy, "Head", parts);
            tempEnemy = new Enemy("Heavy Armor", parts);
            enemies.Add(tempEnemy);
            parts.Clear();

            Faction tempFaction = new Faction("Grineer", enemies);
            factions.Add(tempFaction);
            enemies.Clear();
        }

        public void ImportCorpus(XElement root, List<Part> parts, List<Enemy> enemies)
        {
            Enemy tempEnemy;

            XElement xtemp = root.Element("Corpus");
            // crewman
            XElement xEnemy = xtemp.Element("Crewman");
            ImportEnemy(xEnemy, "Body", parts);
            ImportEnemy(xEnemy, "Head", parts);
            tempEnemy = new Enemy("Crewman", parts);
            enemies.Add(tempEnemy);
            parts.Clear();

            // MOA
            xEnemy = xtemp.Element("MOA");
            ImportEnemy(xEnemy, "Midsection", parts);
            ImportEnemy(xEnemy, "Battery", parts);
            ImportEnemy(xEnemy, "Legs", parts);
            tempEnemy = new Enemy("MOA", parts);
            enemies.Add(tempEnemy);
            parts.Clear();

            // osprey
            xEnemy = xtemp.Element("Osprey");
            ImportEnemy(xEnemy, "Body", parts);
            tempEnemy = new Enemy("Osprey", parts);
            enemies.Add(tempEnemy);
            parts.Clear();

            Faction tempFaction = new Faction("Corpus", enemies);
            factions.Add(tempFaction);
            enemies.Clear();
        }

        public void ImportInfested(XElement root, List<Part> parts, List<Enemy> enemies)
        {
            Enemy tempEnemy;

            XElement xtemp = root.Element("Infested");
            // charger
            XElement xEnemy = xtemp.Element("Charger");
            ImportEnemy(xEnemy, "Body", parts);
            ImportEnemy(xEnemy, "Head", parts);
            tempEnemy = new Enemy("Light Armor", parts);
            enemies.Add(tempEnemy);
            parts.Clear();

            // walker
            xEnemy = xtemp.Element("Walker");
            ImportEnemy(xEnemy, "Body", parts);
            ImportEnemy(xEnemy, "Head", parts);
            tempEnemy = new Enemy("Walker", parts);
            enemies.Add(tempEnemy);
            parts.Clear();

            // crawler
            xEnemy = xtemp.Element("Crawler");
            ImportEnemy(xEnemy, "Body", parts);
            ImportEnemy(xEnemy, "Head", parts);
            ImportEnemy(xEnemy, "Limbs", parts);
            tempEnemy = new Enemy("Crawler", parts);
            enemies.Add(tempEnemy);
            parts.Clear();

            // ancient
            xEnemy = xtemp.Element("Ancient");
            ImportEnemy(xEnemy, "Body", parts);
            ImportEnemy(xEnemy, "Head", parts);
            ImportEnemy(xEnemy, "Lower", parts);
            tempEnemy = new Enemy("Ancient", parts);
            enemies.Add(tempEnemy);
            parts.Clear();

            Faction tempFaction = new Faction("Infested", enemies);
            factions.Add(tempFaction);
            enemies.Clear();
        }

        public void ImportEnemies()
        {
            XElement EnemyRoot = XElement.Load("Resources/XML/Enemies.xml");
            factions.Clear();

            // import temp variables
            List<Part> parts = new List<Part>();
            List<Enemy> enemies = new List<Enemy>();

            ImportGrineer(EnemyRoot, parts, enemies);
            ImportCorpus(EnemyRoot, parts, enemies);
            ImportInfested(EnemyRoot, parts, enemies);
        }

        public void ImportWarframes()
        {
            XElement WarframeRoot = XElement.Load("Resources/XML/Warframes.xml");
            warframes.Clear();

            // import temp variables
            List<int> slots = new List<int>();
            List<Polarity> newPolarities = new List<Polarity>();
            IEnumerable<XElement> ESlot;
            IEnumerable<XElement> EPolarities;
            XAttribute xType;
            XAttribute xName;
            XElement xHealth;
            XElement xShield;
            XElement xEnergy;
            XElement xArmor;
            XElement xRecharge;
            XElement xSpeed;
            XElement xPolarities;
            XElement xAmount;

            IEnumerable<XElement> EWarframes = WarframeRoot.Elements("Warframe");
            foreach (XElement xWarframe in EWarframes)
            {
                // import warframe values
                xName = xWarframe.Attribute("Name");
                xHealth = xWarframe.Element("Health");
                xShield = xWarframe.Element("Shield");
                xEnergy = xWarframe.Element("Energy");
                xArmor = xWarframe.Element("Armor");
                xRecharge = xWarframe.Element("Recharge");
                xSpeed = xWarframe.Element("Speed");

                // import polarities
                xPolarities = xWarframe.Element("Polarities");
                EPolarities = xPolarities.Elements("Polarity");
                foreach (XElement xPolarity in EPolarities)
                {
                    xType = xPolarity.Attribute("Type");
                    xAmount = xPolarity.Element("Amount");

                    ESlot = xPolarity.Elements("Slot");
                    foreach (XElement xSlot in ESlot)
                    {
                        slots.Add(Convert.ToInt32(xSlot.Value));
                    }

                    for (int i = 0; i < Convert.ToInt32(xAmount.Value); ++i)
                    {
                        // update mod slot
                        Polarity newPolarity = new Polarity(Convert.ToInt32(xType.Value), slots[i]);
                        newPolarities.Add(newPolarity);
                    }
                    slots.Clear();
                }

                // TODO: HARD CODING STAM VALUES ATM (STAM VALUES UNKNOWN)
                Warframe newWarframe = new Warframe(xName.Value, 0, false, newPolarities, ObjectType.Warframe,
                    (float)Convert.ToDouble(xHealth.Value),
                    (float)Convert.ToDouble(xShield.Value),
                    (float)Convert.ToDouble(xEnergy.Value),
                    (float)Convert.ToDouble(xArmor.Value), 100.0f,
                    (float)Convert.ToDouble(xRecharge.Value), 10.0f,
                    (float)Convert.ToDouble(xSpeed.Value));

                warframes.Add(newWarframe);
                newPolarities.Clear();
            }
        }

        public void ImportWeapons(IEnumerable<XElement> IEelements, ObjectType Type)
        {
            // TODO: IMPORT GUNS
            XAttribute aName;
            XElement xDmg;
            XElement xFR;
            XElement xAcc;
            XElement xMag;
            XElement xAmmo;
            XElement xReload;
            XElement xCrit;
            XElement xCritMult;
            XElement xChargeDmg;
            XElement xChargeSpeed;
            XElement xPolarities;
            IEnumerable<XElement> IPolarities;
            List<Polarity> newPolarities = new List<Polarity>();
            int slot;
            float chargeDmg = 0, chargeSpeed = 0, accuracy = 0, reload = 0;
            int magazine = 0, ammo = 0;
            foreach (XElement xElement in IEelements)
            {
                aName = xElement.Attribute("Name");
                xDmg = xElement.Element("BaseDamage");
                xFR = xElement.Element("BaseFireRate");
                xAcc = xElement.Element("BaseAccuracy");
                xMag = xElement.Element("BaseClipSize");
                xAmmo = xElement.Element("BaseAmmoCapacity");
                xReload = xElement.Element("BaseReloadSpeed");
                xCrit = xElement.Element("BaseCritChance");
                xCritMult = xElement.Element("BaseCritMultiplier");
                xChargeDmg = xElement.Element("BaseChargeDamage");
                xChargeSpeed = xElement.Element("BaseChargeSpeed");
                //XElement xNumPol = xElement.Element("NumPolarity");

                xPolarities = xElement.Element("Polarities");
                IPolarities = xPolarities.Elements("Polarity");
                slot = 0;
                foreach (XElement xPolarity in IPolarities)
                {
                    XAttribute xType = xPolarity.Attribute("Type");
                    newPolarities.Add(new Polarity(Convert.ToInt32(xType.Value), slot++));
                }
                if (Type == ObjectType.Melee)
                {
                    chargeDmg = Convert.ToSingle(xChargeDmg.Value);
                    chargeSpeed = Convert.ToSingle(xChargeSpeed.Value);
                }
                else if (Type == ObjectType.Rifle)
                {
                    accuracy = Convert.ToSingle(xAcc.Value);
                    magazine = Convert.ToInt32(xMag.Value);
                    ammo = Convert.ToInt32(xAmmo.Value);
                    reload = Convert.ToSingle(xReload.Value);
                }

                Weapon newWeapon = new Weapon(aName.Value,
                    0,
                    false,
                    newPolarities,
                    Type,
                    accuracy,
                    Convert.ToSingle(xDmg.Value),
                    Convert.ToSingle(xCrit.Value),
                    Convert.ToSingle(xCritMult.Value),
                    Convert.ToSingle(xFR.Value),
                    reload,
                    magazine,
                    ammo,
                    chargeDmg,
                    chargeSpeed, 0, 0, 0, 0, 0, 0, 0);

                weapons.Add(newWeapon);
                newPolarities.Clear();
            }
        }

        public void ImportAllWeapons()
        {
            XElement WeaponRoot = XElement.Load("Resources/XML/Weapons.xml");
            weapons.Clear();

            //Load in primary weappons
            XElement xPrimaryWeapons = WeaponRoot.Element("PrimaryWeapons");
            //Load in rifles            
            XElement xWeaponType = xPrimaryWeapons.Element("Rifles");
            IEnumerable<XElement> ePrimaryWeapons = xWeaponType.Elements("Rifle");
            ImportWeapons(ePrimaryWeapons, ObjectType.Rifle);

            //Load in Special Weaopons
            xWeaponType = xPrimaryWeapons.Element("SpecialWeapons");
            ePrimaryWeapons = xWeaponType.Elements("SpecialWeapon");
            ImportWeapons(ePrimaryWeapons, ObjectType.Rifle);

            //Load in shotguns
            xWeaponType = xPrimaryWeapons.Element("Shotguns");
            ePrimaryWeapons = xWeaponType.Elements("Shotgun");
            ImportWeapons(ePrimaryWeapons, ObjectType.Shotgun);

            //Load in secondary weapons
            XElement xSecondaryWeapons = WeaponRoot.Element("SecondaryWeapons");
            //Load in Pistols
            XElement xPistols = xSecondaryWeapons.Element("Pistols");
            //Load in single pistols
            XElement xPistolType = xPistols.Element("Single");
            IEnumerable<XElement> ePistols = xPistolType.Elements("Pistol");
            ImportWeapons(ePistols, ObjectType.Pistol);
            //Load in dual pistols
            xPistolType = xPistols.Element("Dual");
            ePistols = xPistolType.Elements("Pistol");
            ImportWeapons(ePistols, ObjectType.Pistol);

            // Load in MeleeWeapons
            XElement xMeleeWeapons = WeaponRoot.Element("MeleeWeapons");
            // Load in short melee weapons
            XElement xMeleeType = xMeleeWeapons.Element("Short");
            IEnumerable<XElement> eMeleeWeapons = xMeleeType.Elements("ShortMeleeWeapon");
            ImportWeapons(eMeleeWeapons, ObjectType.Melee);
            //Load in long
            xMeleeType = xMeleeWeapons.Element("Long");
            eMeleeWeapons = xMeleeType.Elements("LongMeleeWeapon");
            ImportWeapons(eMeleeWeapons, ObjectType.Melee);
            //Load in dual
            xMeleeType = xMeleeWeapons.Element("Dual");
            eMeleeWeapons = xMeleeType.Elements("DualMeleeWeapon");
            ImportWeapons(eMeleeWeapons, ObjectType.Melee);
            //Load in heavy
            xMeleeType = xMeleeWeapons.Element("Heavy");
            eMeleeWeapons = xMeleeType.Elements("HeavyMeleeWeapon");
            ImportWeapons(eMeleeWeapons, ObjectType.Melee);
        }

        private void ShowWarframeBaseStats(Warframe warframe)
        {
            WarframeLevelNUD.Value = warframe.Level;
            WarframeSCCB.SelectedIndex = Convert.ToInt32(warframe.IsSuperCharged);
            WarframeMPTB.Text = Convert.ToString(warframe.MaxModPoints);
            BaseHealthTB.Text = Convert.ToString(warframe.BaseHealth);
            BaseEnergyTB.Text = Convert.ToString(warframe.BaseEnergy);
            BaseArmorTB.Text = Convert.ToString(warframe.BaseArmor);
            BaseShieldTB.Text = Convert.ToString(warframe.BaseShield);
            BaseStaminaTB.Text = Convert.ToString(warframe.BaseStamina);
            BaseShieldRechargeTB.Text = Convert.ToString(warframe.BaseShieldRecharge);
            BaseStamRechargeTB.Text = Convert.ToString(warframe.BaseStaminaRecharge);
            BaseSpeedTB.Text = Convert.ToString(warframe.BaseSprintSpeed);
        }

        private void ShowUpdatedWarframeStats(Warframe warframe)
        {
            NewHealthTB.Text = Convert.ToString(warframe.Health);
            NewEnergyTB.Text = Convert.ToString(warframe.Energy);
            NewArmorTB.Text = Convert.ToString(warframe.Armor);
            NewShieldTB.Text = Convert.ToString(warframe.Shield);
            NewStaminaTB.Text = Convert.ToString(warframe.Stamina);
            NewShieldRechargeTB.Text = Convert.ToString(warframe.ShieldRecharge);
            NewStamRechargeTB.Text = Convert.ToString(warframe.StaminaRecharge);
            NewSpeedTB.Text = Convert.ToString(warframe.SprintSpeed);
        }

        private void ShowWeaponBaseStats(Weapon weapon)
        {
            // TODO: SHOW WEAPON BASE STATS
            /*
            WeaponLevelNUD.Value = weapon.Level;
            WeaponSCCB.SelectedIndex = Convert.ToInt32(weapon.IsSuperCharged);
            WeaponMPTB.Text = Convert.ToString(weapon.CurrentModPoints);
            BaseDmgTB.Text = Convert.ToString(weapon.BaseDamage);
            BaseAccTB.Text = Convert.ToString(weapon.BaseAccuracy);
            BaseReloadTB.Text = Convert.ToString(weapon.BaseReloadSpeed);
            BaseFireRateTB.Text = Convert.ToString(weapon.BaseFireRate);
            BaseMagTB.Text = Convert.ToString(weapon.BaseMagazineCapacity);
            BaseAmmoCapTB.Text = Convert.ToString(weapon.BaseAmmoCapacity);
            BaseCritTB.Text = Convert.ToString(weapon.BaseCriticalChance);
            BaseCritDmgTB.Text = Convert.ToString(weapon.BaseCriticalDamage);
            BaseChgDmgTB.Text = Convert.ToString(weapon.BaseChargeDamage);
            BaseChgSpeedTB.Text = Convert.ToString(weapon.BaseChargeSpeed);
            BaseFireTB.Text = Convert.ToString(weapon.BaseFireDamage);
            BaseFireTB.Text = Convert.ToString(weapon.BaseFreezeDamage);
            BaseFireTB.Text = Convert.ToString(weapon.BaseElectricDamage);
            BaseFireTB.Text = Convert.ToString(weapon.BaseArmorPierceDamage);
            */
        }

        private void ShowUpdatedWeaponStats(Weapon weapon)
        {
            // TODO: SHOW UPDATED WEAPON STATS
            /*
            WeaponLevelNUD.Value = weapon.Level;
            WeaponSCCB.SelectedIndex = Convert.ToInt32(weapon.IsSuperCharged);
            WeaponMPTB.Text = Convert.ToString(weapon.CurrentModPoints);
            NewDmgTB.Text = Convert.ToString(weapon.Damage);
            NewAccTB.Text = Convert.ToString(weapon.Accuracy);
            NewReloadTB.Text = Convert.ToString(weapon.ReloadSpeed);
            NewFireRateTB.Text = Convert.ToString(weapon.FireRate);
            NewMagTB.Text = Convert.ToString(weapon.MagazineCapacity);
            NewAmmoCapTB.Text = Convert.ToString(weapon.AmmoCapacity);
            NewCritTB.Text = Convert.ToString(weapon.CriticalChance);
            NewCritDmgTB.Text = Convert.ToString(weapon.CriticalDamage);
            NewChgDmgTB.Text = Convert.ToString(weapon.ChargeDamage);
            NewChgSpeedTB.Text = Convert.ToString(weapon.ChargeSpeed);
            NewFireTB.Text = Convert.ToString(weapon.FireDamage);
            NewFireTB.Text = Convert.ToString(weapon.FreezeDamage);
            NewFireTB.Text = Convert.ToString(weapon.ElectricDamage);
            NewFireTB.Text = Convert.ToString(weapon.ArmorPierceDamage);
            */
        }

        private void ShowUpdatedGrineerStats(Faction grineer)
        {
            // TODO: CURRENTLY JUST SHOWING %. NEED TO DO THE MATH
            // Light Armor 
            // Body
            LArmorBodyNormalTB.Text = Convert.ToString(grineer.Enemies[0].Parts[0].Normal);
            LArmorBodyArmorPenTB.Text = Convert.ToString(grineer.Enemies[0].Parts[0].ArmorPen);
            LArmorBodyElectricTB.Text = Convert.ToString(grineer.Enemies[0].Parts[0].Electric);
            LArmorBodyFireTB.Text = Convert.ToString(grineer.Enemies[0].Parts[0].Fire);
            LArmorBodyFrostTB.Text = Convert.ToString(grineer.Enemies[0].Parts[0].Frost);
            // Head
            LArmorHeadNormalTB.Text = Convert.ToString(grineer.Enemies[0].Parts[1].Normal);
            LArmorHeadArmorPenTB.Text = Convert.ToString(grineer.Enemies[0].Parts[1].ArmorPen);
            LArmorHeadElectricTB.Text = Convert.ToString(grineer.Enemies[0].Parts[1].Electric);
            LArmorHeadFireTB.Text = Convert.ToString(grineer.Enemies[0].Parts[1].Fire);
            LArmorHeadFrostTB.Text = Convert.ToString(grineer.Enemies[0].Parts[1].Frost);

            // Medium Armor 
            // Body
            MArmorBodyNormalTB.Text = Convert.ToString(grineer.Enemies[1].Parts[0].Normal);
            MArmorBodyArmorPenTB.Text = Convert.ToString(grineer.Enemies[1].Parts[0].ArmorPen);
            MArmorBodyElectricTB.Text = Convert.ToString(grineer.Enemies[1].Parts[0].Electric);
            MArmorBodyFireTB.Text = Convert.ToString(grineer.Enemies[1].Parts[0].Fire);
            MArmorBodyFrostTB.Text = Convert.ToString(grineer.Enemies[1].Parts[0].Frost);
            // Head
            MArmorHeadNormalTB.Text = Convert.ToString(grineer.Enemies[1].Parts[1].Normal);
            MArmorHeadArmorPenTB.Text = Convert.ToString(grineer.Enemies[1].Parts[1].ArmorPen);
            MArmorHeadElectricTB.Text = Convert.ToString(grineer.Enemies[1].Parts[1].Electric);
            MArmorHeadFireTB.Text = Convert.ToString(grineer.Enemies[1].Parts[1].Fire);
            MArmorHeadFrostTB.Text = Convert.ToString(grineer.Enemies[1].Parts[1].Frost);

            // Heavy Armor 
            // Body
            HArmorBodyNormalTB.Text = Convert.ToString(grineer.Enemies[2].Parts[0].Normal);
            HArmorBodyArmorPenTB.Text = Convert.ToString(grineer.Enemies[2].Parts[0].ArmorPen);
            HArmorBodyElectricTB.Text = Convert.ToString(grineer.Enemies[2].Parts[0].Electric);
            HArmorBodyFireTB.Text = Convert.ToString(grineer.Enemies[2].Parts[0].Fire);
            HArmorBodyFrostTB.Text = Convert.ToString(grineer.Enemies[2].Parts[0].Frost);
            // Head
            HArmorHeadNormalTB.Text = Convert.ToString(grineer.Enemies[2].Parts[1].Normal);
            HArmorHeadArmorPenTB.Text = Convert.ToString(grineer.Enemies[2].Parts[1].ArmorPen);
            HArmorHeadElectricTB.Text = Convert.ToString(grineer.Enemies[2].Parts[1].Electric);
            HArmorHeadFireTB.Text = Convert.ToString(grineer.Enemies[2].Parts[1].Fire);
            HArmorHeadFrostTB.Text = Convert.ToString(grineer.Enemies[2].Parts[1].Frost);
        }

        private void ShowUpdatedCorpusStats(Faction corpus)
        {
            // TODO: CURRENTLY JUST SHOWING %. NEED TO DO THE MATH
            // Crewman 
            // Body
            CrewmanBodyNormalTB.Text = Convert.ToString(corpus.Enemies[0].Parts[0].Normal);
            CrewmanBodyArmorPenTB.Text = Convert.ToString(corpus.Enemies[0].Parts[0].ArmorPen);
            CrewmanBodyElectricTB.Text = Convert.ToString(corpus.Enemies[0].Parts[0].Electric);
            CrewmanBodyFireTB.Text = Convert.ToString(corpus.Enemies[0].Parts[0].Fire);
            CrewmanBodyFrostTB.Text = Convert.ToString(corpus.Enemies[0].Parts[0].Frost);
            // Head
            CrewmanHeadNormalTB.Text = Convert.ToString(corpus.Enemies[0].Parts[1].Normal);
            CrewmanHeadArmorPenTB.Text = Convert.ToString(corpus.Enemies[0].Parts[1].ArmorPen);
            CrewmanHeadElectricTB.Text = Convert.ToString(corpus.Enemies[0].Parts[1].Electric);
            CrewmanHeadFireTB.Text = Convert.ToString(corpus.Enemies[0].Parts[1].Fire);
            CrewmanHeadFrostTB.Text = Convert.ToString(corpus.Enemies[0].Parts[1].Frost);

            // MOA
            // Body
            MOAMidSectionNormalTB.Text = Convert.ToString(corpus.Enemies[1].Parts[0].Normal);
            MOAMidSectionArmorPenTB.Text = Convert.ToString(corpus.Enemies[1].Parts[0].ArmorPen);
            MOAMidSectionElectricTB.Text = Convert.ToString(corpus.Enemies[1].Parts[0].Electric);
            MOAMidSectionFireTB.Text = Convert.ToString(corpus.Enemies[1].Parts[0].Fire);
            MOAMidSectionFrostTB.Text = Convert.ToString(corpus.Enemies[1].Parts[0].Frost);
            // 
            MOABatteryNormalTB.Text = Convert.ToString(corpus.Enemies[1].Parts[1].Normal);
            MOABatteryArmorPenTB.Text = Convert.ToString(corpus.Enemies[1].Parts[1].ArmorPen);
            MOABatteryElectricTB.Text = Convert.ToString(corpus.Enemies[1].Parts[1].Electric);
            MOABatteryFireTB.Text = Convert.ToString(corpus.Enemies[1].Parts[1].Fire);
            MOABatteryFrostTB.Text = Convert.ToString(corpus.Enemies[1].Parts[1].Frost);
            //
            MOALegsNormalTB.Text = Convert.ToString(corpus.Enemies[1].Parts[2].Normal);
            MOALegsArmorPenTB.Text = Convert.ToString(corpus.Enemies[1].Parts[2].ArmorPen);
            MOALegsElectricTB.Text = Convert.ToString(corpus.Enemies[1].Parts[2].Electric);
            MOALegsFireTB.Text = Convert.ToString(corpus.Enemies[1].Parts[2].Fire);
            MOALegsFrostTB.Text = Convert.ToString(corpus.Enemies[1].Parts[2].Frost);

            // Osprey
            // Body
            OspreyBodyNormalTB.Text = Convert.ToString(corpus.Enemies[2].Parts[0].Normal);
            OspreyBodyArmorPenTB.Text = Convert.ToString(corpus.Enemies[2].Parts[0].ArmorPen);
            OspreyBodyElectricTB.Text = Convert.ToString(corpus.Enemies[2].Parts[0].Electric);
            OspreyBodyFireTB.Text = Convert.ToString(corpus.Enemies[2].Parts[0].Fire);
            OspreyBodyFrostTB.Text = Convert.ToString(corpus.Enemies[2].Parts[0].Frost);
        }

        private void ShowUpdatedInfestedStats(Faction infested)
        {
            // TODO: CURRENTLY JUST SHOWING %. NEED TO DO THE MATH
            // Charger
            // Body
            ChargerBodyNormalTB.Text = Convert.ToString(infested.Enemies[0].Parts[0].Normal);
            ChargerBodyArmorPenTB.Text = Convert.ToString(infested.Enemies[0].Parts[0].ArmorPen);
            ChargerBodyElectricTB.Text = Convert.ToString(infested.Enemies[0].Parts[0].Electric);
            ChargerBodyFireTB.Text = Convert.ToString(infested.Enemies[0].Parts[0].Fire);
            ChargerBodyFrostTB.Text = Convert.ToString(infested.Enemies[0].Parts[0].Frost);
            // Head
            ChargerHeadNormalTB.Text = Convert.ToString(infested.Enemies[0].Parts[1].Normal);
            ChargerHeadArmorPenTB.Text = Convert.ToString(infested.Enemies[0].Parts[1].ArmorPen);
            ChargerHeadElectricTB.Text = Convert.ToString(infested.Enemies[0].Parts[1].Electric);
            ChargerHeadFireTB.Text = Convert.ToString(infested.Enemies[0].Parts[1].Fire);
            ChargerHeadFrostTB.Text = Convert.ToString(infested.Enemies[0].Parts[1].Frost);

            // Walker
            // Body
            WalkerBodyNormalTB.Text = Convert.ToString(infested.Enemies[1].Parts[0].Normal);
            WalkerBodyArmorPenTB.Text = Convert.ToString(infested.Enemies[1].Parts[0].ArmorPen);
            WalkerBodyElectricTB.Text = Convert.ToString(infested.Enemies[1].Parts[0].Electric);
            WalkerBodyFireTB.Text = Convert.ToString(infested.Enemies[1].Parts[0].Fire);
            WalkerBodyFrostTB.Text = Convert.ToString(infested.Enemies[1].Parts[0].Frost);
            // Head
            WalkerHeadNormalTB.Text = Convert.ToString(infested.Enemies[1].Parts[1].Normal);
            WalkerHeadArmorPenTB.Text = Convert.ToString(infested.Enemies[1].Parts[1].ArmorPen);
            WalkerHeadElectricTB.Text = Convert.ToString(infested.Enemies[1].Parts[1].Electric);
            WalkerHeadFireTB.Text = Convert.ToString(infested.Enemies[1].Parts[1].Fire);
            WalkerHeadFrostTB.Text = Convert.ToString(infested.Enemies[1].Parts[1].Frost);

            // Ancient
            // Body
            AncientBodyNormalTB.Text = Convert.ToString(infested.Enemies[2].Parts[0].Normal);
            AncientBodyArmorPenTB.Text = Convert.ToString(infested.Enemies[2].Parts[0].ArmorPen);
            AncientBodyElectricTB.Text = Convert.ToString(infested.Enemies[2].Parts[0].Electric);
            AncientBodyFireTB.Text = Convert.ToString(infested.Enemies[2].Parts[0].Fire);
            AncientBodyFrostTB.Text = Convert.ToString(infested.Enemies[2].Parts[0].Frost);
            // Head
            AncientHeadNormalTB.Text = Convert.ToString(infested.Enemies[2].Parts[1].Normal);
            AncientHeadArmorPenTB.Text = Convert.ToString(infested.Enemies[2].Parts[1].ArmorPen);
            AncientHeadElectricTB.Text = Convert.ToString(infested.Enemies[2].Parts[1].Electric);
            AncientHeadFireTB.Text = Convert.ToString(infested.Enemies[2].Parts[1].Fire);
            AncientHeadFrostTB.Text = Convert.ToString(infested.Enemies[2].Parts[1].Frost);
            // Lower Legs
            AncientLowerNormalTB.Text = Convert.ToString(infested.Enemies[2].Parts[2].Normal);
            AncientLowerArmorPenTB.Text = Convert.ToString(infested.Enemies[2].Parts[2].ArmorPen);
            AncientLowerElectricTB.Text = Convert.ToString(infested.Enemies[2].Parts[2].Electric);
            AncientLowerFireTB.Text = Convert.ToString(infested.Enemies[2].Parts[2].Fire);
            AncientLowerFrostTB.Text = Convert.ToString(infested.Enemies[2].Parts[2].Frost);

            // Crawler
            // Body
            CrawlerBodyNormalTB.Text = Convert.ToString(infested.Enemies[3].Parts[0].Normal);
            CrawlerBodyArmorPenTB.Text = Convert.ToString(infested.Enemies[3].Parts[0].ArmorPen);
            CrawlerBodyElectricTB.Text = Convert.ToString(infested.Enemies[3].Parts[0].Electric);
            CrawlerBodyFireTB.Text = Convert.ToString(infested.Enemies[3].Parts[0].Fire);
            CrawlerBodyFrostTB.Text = Convert.ToString(infested.Enemies[3].Parts[0].Frost);
            // Head
            CrawlerHeadNormalTB.Text = Convert.ToString(infested.Enemies[3].Parts[1].Normal);
            CrawlerHeadArmorPenTB.Text = Convert.ToString(infested.Enemies[3].Parts[1].ArmorPen);
            CrawlerHeadElectricTB.Text = Convert.ToString(infested.Enemies[3].Parts[1].Electric);
            CrawlerHeadFireTB.Text = Convert.ToString(infested.Enemies[3].Parts[1].Fire);
            CrawlerHeadFrostTB.Text = Convert.ToString(infested.Enemies[3].Parts[1].Frost);
            // Limbs
            CrawlerLimbsNormalTB.Text = Convert.ToString(infested.Enemies[3].Parts[2].Normal);
            CrawlerLimbsArmorPenTB.Text = Convert.ToString(infested.Enemies[3].Parts[2].ArmorPen);
            CrawlerLimbsElectricTB.Text = Convert.ToString(infested.Enemies[3].Parts[2].Electric);
            CrawlerLimbsFireTB.Text = Convert.ToString(infested.Enemies[3].Parts[2].Fire);
            CrawlerLimbsFrostTB.Text = Convert.ToString(infested.Enemies[3].Parts[2].Frost);
        }

        public void SetPolarities(object obj)
        {
            // warframe
            if (WarframeWeaponTab.SelectedIndex == 0)
            {
                Warframe warframe = (Warframe)obj;
                string filepath = "Resources/Polarities/";
                string filename = ".png";
                string name;

                // set polarities to buttons
                for (int i = 0; i < warframe.Polarities.Count; ++i)
                    WarframeButtonPolarities[warframe.Polarities[i].Slot] = warframe.Polarities[i];

                // if no mods in slot: clears mod images and loads in polarities
                // if there is mod: loads in current warframe's mod images and cost number
                // ability polarity mod slots: 1,5,6,10
                // other polarity mod slots: 2,3,7
                if (warframes[iCurrentWarframe].Mods[0].Picture != null)
                {
                    WarframeModButton1.BackgroundImage = warframes[iCurrentWarframe].Mods[0].Picture;
                    WarframeModButton1.Image = warframe.Mods[0].Polaritytype.Picture[warframe.Polarities[0].CurrentPicture];
                    name = Convert.ToString(warframes[iCurrentWarframe].Mods[0].Cost);
                    Mod1PB.Image = Image.FromFile(filepath + name + filename);
                }
                else
                {
                    WarframeModButton1.BackgroundImage = null;
                    WarframeModButton1.Image = warframe.Polarities[0].Picture[0];
                    Mod1PB.Image = null;
                }

                if (warframes[iCurrentWarframe].Mods[1].Picture != null)
                {
                    WarframeModButton2.BackgroundImage = warframes[iCurrentWarframe].Mods[1].Picture;
                    WarframeModButton2.Image = warframe.Mods[1].Polaritytype.Picture[warframe.Polarities[4].CurrentPicture];
                    name = Convert.ToString(warframes[iCurrentWarframe].Mods[1].Cost);
                    Mod2PB.Image = Image.FromFile(filepath + name + filename);
                }
                else
                {
                    WarframeModButton2.BackgroundImage = null;
                    WarframeModButton2.Image = warframe.Polarities[4].Picture[0];
                    Mod2PB.Image = null;
                }

                if (warframes[iCurrentWarframe].Mods[2].Picture != null)
                {
                    WarframeModButton3.BackgroundImage = warframes[iCurrentWarframe].Mods[2].Picture;
                    // error check for primes
                    if (warframe.Polarities.Count > 6)
                        WarframeModButton3.Image = warframe.Mods[2].Polaritytype.Picture[warframe.Polarities[6].CurrentPicture];
                    else
                        WarframeModButton3.Image = null;
                    name = Convert.ToString(warframes[iCurrentWarframe].Mods[2].Cost);
                    Mod3PB.Image = Image.FromFile(filepath + name + filename);
                }
                else
                {
                    // error check for primes
                    if (warframe.Polarities.Count > 6)
                        WarframeModButton3.Image = warframe.Polarities[6].Picture[0];
                    else
                        WarframeModButton3.Image = null;
                    WarframeModButton3.BackgroundImage = null;
                    Mod3PB.Image = null;
                }

                if (warframes[iCurrentWarframe].Mods[3].Picture != null)
                {
                    WarframeModButton4.BackgroundImage = warframes[iCurrentWarframe].Mods[3].Picture;
                    name = Convert.ToString(warframes[iCurrentWarframe].Mods[3].Cost);
                    Mod4PB.Image = Image.FromFile(filepath + name + filename);
                }
                else
                {
                    WarframeModButton4.BackgroundImage = null;
                    Mod4PB.Image = null;
                }

                if (warframes[iCurrentWarframe].Mods[4].Picture != null)
                {
                    WarframeModButton5.BackgroundImage = warframes[iCurrentWarframe].Mods[4].Picture;
                    WarframeModButton5.Image = warframe.Mods[4].Polaritytype.Picture[warframe.Polarities[1].CurrentPicture];
                    name = Convert.ToString(warframes[iCurrentWarframe].Mods[4].Cost);
                    Mod5PB.Image = Image.FromFile(filepath + name + filename);
                }
                else
                {
                    WarframeModButton5.BackgroundImage = null;
                    WarframeModButton5.Image = warframe.Polarities[1].Picture[0];
                    Mod5PB.Image = null;
                }

                if (warframes[iCurrentWarframe].Mods[5].Picture != null)
                {
                    WarframeModButton6.BackgroundImage = warframes[iCurrentWarframe].Mods[5].Picture;
                    WarframeModButton6.Image = warframe.Mods[5].Polaritytype.Picture[warframe.Polarities[2].CurrentPicture];
                    name = Convert.ToString(warframes[iCurrentWarframe].Mods[5].Cost);
                    Mod6PB.Image = Image.FromFile(filepath + name + filename);
                }
                else
                {
                    WarframeModButton6.BackgroundImage = null;
                    WarframeModButton6.Image = warframe.Polarities[2].Picture[0];
                    Mod6PB.Image = null;
                }

                if (warframes[iCurrentWarframe].Mods[6].Picture != null)
                {
                    WarframeModButton7.BackgroundImage = warframes[iCurrentWarframe].Mods[6].Picture;
                    WarframeModButton7.Image = warframe.Mods[6].Polaritytype.Picture[warframe.Polarities[5].CurrentPicture];
                    name = Convert.ToString(warframes[iCurrentWarframe].Mods[6].Cost);
                    Mod7PB.Image = Image.FromFile(filepath + name + filename);
                }
                else
                {
                    WarframeModButton7.BackgroundImage = null;
                    WarframeModButton7.Image = warframe.Polarities[5].Picture[0];
                    Mod7PB.Image = null;
                }

                if (warframes[iCurrentWarframe].Mods[7].Picture != null)
                {
                    WarframeModButton8.BackgroundImage = warframes[iCurrentWarframe].Mods[7].Picture;
                    name = Convert.ToString(warframes[iCurrentWarframe].Mods[7].Cost);
                    Mod8PB.Image = Image.FromFile(filepath + name + filename);
                }
                else
                {
                    WarframeModButton8.BackgroundImage = null;
                    Mod8PB.Image = null;
                }

                if (warframes[iCurrentWarframe].Mods[8].Picture != null)
                {
                    WarframeModButton9.BackgroundImage = warframes[iCurrentWarframe].Mods[8].Picture;
                    name = Convert.ToString(warframes[iCurrentWarframe].Mods[8].Cost);
                    Mod9PB.Image = Image.FromFile(filepath + name + filename);
                }
                else
                {
                    WarframeModButton9.BackgroundImage = null;
                    Mod9PB.Image = null;
                }

                if (warframes[iCurrentWarframe].Mods[9].Picture != null)
                {
                    WarframeModButton10.BackgroundImage = warframes[iCurrentWarframe].Mods[9].Picture;
                    WarframeModButton10.Image = warframe.Mods[9].Polaritytype.Picture[warframe.Polarities[3].CurrentPicture];
                    name = Convert.ToString(warframes[iCurrentWarframe].Mods[9].Cost);
                    Mod10PB.Image = Image.FromFile(filepath + name + filename);
                }
                else
                {
                    WarframeModButton10.BackgroundImage = null;
                    WarframeModButton10.Image = warframe.Polarities[3].Picture[0];
                    Mod10PB.Image = null;
                }
            }
            // weapon
            else
            {
                // TODO: NEED TO LOAD IN WEAPONS
                /*
                Weapon weapon = (Weapon)obj;
                WeaponModButton1.Image = weapon.Polarities[0].Picture;
                // Special Case for Primes
                if(weapon.Polarities.Count > 2)
                    WeaponModButton5.Image = weapon.Polarities[1].Picture;
                else
                    WeaponModButton5.Image = null;
                */
            }
        }

        public void ModForm_AddMod(object sender, EventArgs e)
        {
            ModForm tempModForm = sender as ModForm;
            if (tempModForm != null)
            {
                // Warframe Mod || Sentinel Mod
                if (tempModForm.ModTC.SelectedIndex == 0 || tempModForm.ModTC.SelectedIndex == 5)
                {
                    // ERROR CHECKS
                    //check if the same mod is already installed
                    for (int i = 0; i < warframes[iCurrentWarframe].Mods.Count; ++i)
                    {
                        if (warframes[iCurrentWarframe].Mods[i].Name == tempModForm.Mods[tempModForm.ModTC.SelectedIndex][tempModForm.iCurrentwarframeMod].Name)
                        {
                            MessageBox.Show("Same Mod Already Installed!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return; 
                        }
                    }

                    // ERROR CHECKS
                    // check if there are enough mod points
                    if (warframes[iCurrentWarframe].CurrentModPoints < tempModForm.Mods[tempModForm.ModTC.SelectedIndex][tempModForm.iCurrentwarframeMod].BaseCost)
                    {
                        MessageBox.Show("Not Enough Mod Points", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }

                    // if changing mods, return the old mod points
                    if(warframes[iCurrentWarframe].Mods[iCurrentModSlot].Type != ModType.None)
                    {
                        if (WarframeButtonPolarities[iCurrentModSlot].Type == warframes[iCurrentWarframe].Mods[iCurrentModSlot].Polaritytype.Type)
                            warframes[iCurrentWarframe].Mods[iCurrentModSlot].Cost = (int)Math.Round((float)warframes[iCurrentWarframe].Mods[iCurrentModSlot].BaseCost * 0.5f, MidpointRounding.AwayFromZero);
                        else if (WarframeButtonPolarities[iCurrentModSlot].Type == PolarityType.None)
                            warframes[iCurrentWarframe].Mods[iCurrentModSlot].Cost = warframes[iCurrentWarframe].Mods[iCurrentModSlot].BaseCost;
                        else
                            warframes[iCurrentWarframe].Mods[iCurrentModSlot].Cost = (int)Math.Round(warframes[iCurrentWarframe].Mods[iCurrentModSlot].BaseCost + (warframes[iCurrentWarframe].Mods[iCurrentModSlot].BaseCost * 0.25f), MidpointRounding.AwayFromZero);

                        warframes[iCurrentWarframe].CurrentModPoints += warframes[iCurrentWarframe].Mods[iCurrentModSlot].Cost;
                    }

                    // add the new mod to the warframe
                    tempModForm.Mods[tempModForm.ModTC.SelectedIndex][tempModForm.iCurrentwarframeMod].ModifyStat(warframes[iCurrentWarframe]);
                    warframes[iCurrentWarframe].Mods[iCurrentModSlot] = tempModForm.Mods[tempModForm.ModTC.SelectedIndex][tempModForm.iCurrentwarframeMod];

                    // if the polarity is the same then reduce the cost by 50% || if no polarity keep the same cost || if the polarity is different then increase the cost by 25%
                    if (WarframeButtonPolarities[iCurrentModSlot].Type == warframes[iCurrentWarframe].Mods[iCurrentModSlot].Polaritytype.Type)
                    {
                        warframes[iCurrentWarframe].Mods[iCurrentModSlot].Cost = (int)Math.Round((float)warframes[iCurrentWarframe].Mods[iCurrentModSlot].BaseCost * 0.5f, MidpointRounding.AwayFromZero);
                        warframes[iCurrentWarframe].CurrentModPoints -= warframes[iCurrentWarframe].Mods[iCurrentModSlot].Cost;
                        WarframeButtonPolarities[iCurrentModSlot].CurrentPicture = 1;
                    }
                    else if (WarframeButtonPolarities[iCurrentModSlot].Type == PolarityType.None)
                    {
                        warframes[iCurrentWarframe].Mods[iCurrentModSlot].Cost = warframes[iCurrentWarframe].Mods[iCurrentModSlot].BaseCost;
                        warframes[iCurrentWarframe].CurrentModPoints -= warframes[iCurrentWarframe].Mods[iCurrentModSlot].Cost;
                        WarframeButtonPolarities[iCurrentModSlot].CurrentPicture = 0;
                    }
                    else
                    {
                        warframes[iCurrentWarframe].Mods[iCurrentModSlot].Cost = (int)Math.Round(warframes[iCurrentWarframe].Mods[iCurrentModSlot].BaseCost + (warframes[iCurrentWarframe].Mods[iCurrentModSlot].BaseCost * 0.25f), MidpointRounding.AwayFromZero);
                        warframes[iCurrentWarframe].CurrentModPoints -= warframes[iCurrentWarframe].Mods[iCurrentModSlot].Cost;
                        WarframeButtonPolarities[iCurrentModSlot].CurrentPicture = 2;
                    }
                    
                    // change the mod button picture
                    // remove polarity picture and add the cost number
                    // ability polarity mod slots: 1,5,6,10
                    // other polarity mod slots: 2,3,7
                    string filepath = "Resources/Polarities/";
                    string filename = ".png";
                    string name = Convert.ToString(warframes[iCurrentWarframe].Mods[iCurrentModSlot].Cost);
                    switch (iCurrentModSlot)
                    {
                        case 0:
                            WarframeModButton1.BackgroundImage = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Picture;
                            WarframeModButton1.Image = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Polaritytype.Picture[warframes[iCurrentWarframe].Polarities[0].CurrentPicture];
                            Mod1PB.Image = Image.FromFile(filepath + name + filename);
                            break;
                        case 1:
                            WarframeModButton2.BackgroundImage = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Picture;
                            WarframeModButton2.Image = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Polaritytype.Picture[warframes[iCurrentWarframe].Polarities[4].CurrentPicture];
                            Mod2PB.Image = Image.FromFile(filepath + name + filename);
                            break;
                        case 2:
                            WarframeModButton3.BackgroundImage = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Picture;
                            // error check for primes
                            if (warframes[iCurrentWarframe].Polarities.Count > 6)
                                WarframeModButton3.Image = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Polaritytype.Picture[warframes[iCurrentWarframe].Polarities[6].CurrentPicture];
                            else
                                WarframeModButton3.Image = null;

                            Mod3PB.Image = Image.FromFile(filepath + name + filename);
                            break;
                        case 3:
                            WarframeModButton4.BackgroundImage = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Picture;
                            Mod4PB.Image = Image.FromFile(filepath + name + filename);
                            break;
                        case 4:
                            WarframeModButton5.BackgroundImage = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Picture;
                            WarframeModButton5.Image = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Polaritytype.Picture[warframes[iCurrentWarframe].Polarities[1].CurrentPicture];
                            Mod5PB.Image = Image.FromFile(filepath + name + filename);
                            break;
                        case 5:
                            WarframeModButton6.BackgroundImage = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Picture;
                            WarframeModButton6.Image = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Polaritytype.Picture[warframes[iCurrentWarframe].Polarities[2].CurrentPicture];
                            Mod6PB.Image = Image.FromFile(filepath + name + filename);
                            break;
                        case 6:
                            WarframeModButton7.BackgroundImage = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Picture;
                            WarframeModButton7.Image = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Polaritytype.Picture[warframes[iCurrentWarframe].Polarities[5].CurrentPicture];
                            Mod7PB.Image = Image.FromFile(filepath + name + filename);
                            break;
                        case 7:
                            WarframeModButton8.BackgroundImage = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Picture;
                            Mod8PB.Image = Image.FromFile(filepath + name + filename);
                            break;
                        case 8:
                            WarframeModButton9.BackgroundImage = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Picture;
                            Mod9PB.Image = Image.FromFile(filepath + name + filename);
                            break;
                        case 9:
                            WarframeModButton10.BackgroundImage = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Picture;
                            WarframeModButton10.Image = warframes[iCurrentWarframe].Mods[iCurrentModSlot].Polaritytype.Picture[warframes[iCurrentWarframe].Polarities[3].CurrentPicture];
                            Mod10PB.Image = Image.FromFile(filepath + name + filename);
                            break;
                    }

                    // update current mod label text
                    CurrentModPointsLabel.Text = Convert.ToString(warframes[iCurrentWarframe].CurrentModPoints);

                    // close the mod window
                    modWindow.Close();
                }
                // Weapon Mods (Rifle, Shotgun, Pistol, Melee)
                else
                {
                    // TODO: NEED TO LOAD IN WEAPONS
                }

                // update the new stat textboxes
                ShowUpdatedWarframeStats(warframes[iCurrentWarframe]);
            }
        }

        public void ModForm_RemoveMod(object sender, EventArgs e)
        {
            // TODO: REMOVE MOD
        }

        private void CreateModWindow(int currentModSlot, ModType currentmodtype)
        {
            // Open Mod Window
            if (modWindow == null)
            {
                modWindow = new ModForm();
                modWindow.AddMod += new EventHandler(ModForm_AddMod);
                modWindow.RemoveMod += new EventHandler(ModForm_RemoveMod);
            }

            // disable mod tabs based on the object type
            for (int i = 0; i < modWindow.ModTC.TabCount; ++i)
            {
                if (currentmodtype != (ModType)i)
                    modWindow.ModTC.TabPages[i].Enabled = false;
            }

            iCurrentModSlot = currentModSlot;

            // TODO: SET THE CURRENT MOD SELECTED
            if (currentmodtype == ModType.Warframe)
            {
                if (warframes[iCurrentWarframe].Mods[currentModSlot].Type != ModType.None)
                {
                    //modWindow.ModTC.SelectedIndex = ;
                    //modWindow.WarframeModLB.SelectedIndex = ;
                }
                else
                {
                    modWindow.ModTC.SelectedIndex = 0;
                    modWindow.WarframeModLB.SelectedIndex = 0;
                }
            }

            // show the window
            modWindow.ShowDialog();
        }

        private void WarframeModButton1_Click(object sender, EventArgs e)
        {
            CreateModWindow(0, ModType.Warframe);
            
        }

        private void WarframeModButton2_Click(object sender, EventArgs e)
        {
            CreateModWindow(1, ModType.Warframe);
        }

        private void WarframeModButton3_Click(object sender, EventArgs e)
        {
            CreateModWindow(2, ModType.Warframe);
        }

        private void WarframeModButton4_Click(object sender, EventArgs e)
        {
            CreateModWindow(3, ModType.Warframe);
        }

        private void WarframeModButton5_Click(object sender, EventArgs e)
        {
            CreateModWindow(4, ModType.Warframe);
        }

        private void WarframeModButton6_Click(object sender, EventArgs e)
        {
            CreateModWindow(5, ModType.Warframe);
        }

        private void WarframeModButton7_Click(object sender, EventArgs e)
        {
            CreateModWindow(6, ModType.Warframe);
        }

        private void WarframeModButton8_Click(object sender, EventArgs e)
        {
            CreateModWindow(7, ModType.Warframe);
        }

        private void WarframeModButton9_Click(object sender, EventArgs e)
        {
            CreateModWindow(8, ModType.Warframe);
        }

        private void WarframeModButton10_Click(object sender, EventArgs e)
        {
            CreateModWindow(9, ModType.Warframe);
        }

        private void WeaponModButton1_Click(object sender, EventArgs e)
        {
            // TODO: LOAD IN WEAPONS
            //CreateModWindow(0, (ModType)(weapons[iCurrentWeapon].Type + 1));
        }

        private void WeaponModButton2_Click(object sender, EventArgs e)
        {
            // TODO: LOAD IN WEAPONS
            //CreateModWindow(1, (ModType)(weapons[iCurrentWeapon].Type + 1));
        }

        private void WeaponModButton3_Click(object sender, EventArgs e)
        {
            // TODO: LOAD IN WEAPONS
            //CreateModWindow(2, (ModType)(weapons[iCurrentWeapon].Type + 1));
        }

        private void WeaponModButton4_Click(object sender, EventArgs e)
        {
            // TODO: LOAD IN WEAPONS
            //CreateModWindow(3, (ModType)(weapons[iCurrentWeapon].Type + 1));
        }

        private void WeaponModButton5_Click(object sender, EventArgs e)
        {
            // TODO: LOAD IN WEAPONS
            //CreateModWindow(4, (ModType)(weapons[iCurrentWeapon].Type + 1));
        }

        private void WeaponModButton6_Click(object sender, EventArgs e)
        {
            // TODO: LOAD IN WEAPONS
            //CreateModWindow(5, (ModType)(weapons[iCurrentWeapon].Type + 1));
        }

        private void WeaponModButton7_Click(object sender, EventArgs e)
        {
            // TODO: LOAD IN WEAPONS
            //CreateModWindow(6, (ModType)(weapons[iCurrentWeapon].Type + 1));
        }

        private void WeaponModButton8_Click(object sender, EventArgs e)
        {
            // TODO: LOAD IN WEAPONS
            //CreateModWindow(7, (ModType)(weapons[iCurrentWeapon].Type + 1));
        }

        private void WarframeCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            // set current warframe and set all stats
            iCurrentWarframe = WarframeCB.SelectedIndex;
            SetPolarities(warframes[iCurrentWarframe]);
            ShowWarframeBaseStats(warframes[iCurrentWarframe]);
            ShowUpdatedWarframeStats(warframes[iCurrentWarframe]);
        }

        private void WarframeLevelNUD_ValueChanged(object sender, EventArgs e)
        {
            // local temp variables
            int valuePerLevel;
            int max;
            float levels;
            int valueToAdd;

            // update mod points when warframe is supercharged
            if (warframes[iCurrentWarframe].IsSuperCharged == true)
                max = Convert.ToInt32(WarframeLevelNUD.Value) * 2;
            else
                max = Convert.ToInt32(WarframeLevelNUD.Value);

            // update current mod points
            warframes[iCurrentWarframe].CurrentModPoints = max;
            for (int i = 0; i < warframes[iCurrentWarframe].Mods.Count; ++i)
                warframes[iCurrentWarframe].CurrentModPoints -= warframes[iCurrentWarframe].Mods[i].Cost;

            // ERROR CHECK
            // make sure theres enough mod points
            if (warframes[iCurrentWarframe].CurrentModPoints < 0)
            {
                WarframeLevelNUD.Value = warframes[iCurrentWarframe].Level;
                warframes[iCurrentWarframe].CurrentModPoints = 0;
                return;
            }

            // update warframe level
            warframes[iCurrentWarframe].Level = Convert.ToInt32(WarframeLevelNUD.Value);
            warframes[iCurrentWarframe].MaxModPoints = max;

            // health 1,4,7 (3n+1)
            max = (int)(warframes[iCurrentWarframe].BaseHealth + (warframes[iCurrentWarframe].BaseHealth * 2.0f));
            valuePerLevel = (int)((max - warframes[iCurrentWarframe].BaseHealth) / 10.0f);
            levels = (warframes[iCurrentWarframe].Level - 1) / 3.0f;
            // special check for level 0
            float temp = levels + 1.0f;
            if (warframes[iCurrentWarframe].Level == 0)
                temp = 0;
            valueToAdd = valuePerLevel * (int)temp;
            warframes[iCurrentWarframe].Health = warframes[iCurrentWarframe].BaseHealth + valueToAdd;

            // shield 2,5,8 (3n-1)
            max = (int)(warframes[iCurrentWarframe].BaseShield + (warframes[iCurrentWarframe].BaseShield * 2.0f));
            valuePerLevel = (int)((max - warframes[iCurrentWarframe].BaseShield) / 10.0f);
            levels = (warframes[iCurrentWarframe].Level + 1) / 3.0f;
            valueToAdd = valuePerLevel * (int)(levels);
            warframes[iCurrentWarframe].Shield = warframes[iCurrentWarframe].BaseShield + valueToAdd;

            //energy 3,6,9 (3n)
            max = (int)(warframes[iCurrentWarframe].BaseEnergy + (warframes[iCurrentWarframe].BaseEnergy * 0.5f));
            valuePerLevel = (int)((max - warframes[iCurrentWarframe].BaseEnergy) / 10.0f);
            levels = (warframes[iCurrentWarframe].Level / 3.0f);
            valueToAdd = valuePerLevel * (int)(levels);
            warframes[iCurrentWarframe].Energy = warframes[iCurrentWarframe].BaseEnergy + valueToAdd;

            // update the text boxes
            WarframeMPTB.Text = Convert.ToString(warframes[iCurrentWarframe].MaxModPoints);
            CurrentModPointsLabel.Text = Convert.ToString(warframes[iCurrentWarframe].CurrentModPoints);
            ShowUpdatedWarframeStats(warframes[iCurrentWarframe]);
        }

        private void WarframeSCCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            // check if the warframe is supercharged
            if (warframes[iCurrentWarframe].IsSuperCharged != Convert.ToBoolean(WarframeSCCB.SelectedIndex))
            {
                warframes[iCurrentWarframe].IsSuperCharged = Convert.ToBoolean(WarframeSCCB.SelectedIndex);
                // if it is update the mod points
                if (warframes[iCurrentWarframe].IsSuperCharged)
                {
                    warframes[iCurrentWarframe].MaxModPoints += warframes[iCurrentWarframe].Level;
                    warframes[iCurrentWarframe].CurrentModPoints += warframes[iCurrentWarframe].Level;
                }
                else
                {
                    warframes[iCurrentWarframe].MaxModPoints -= warframes[iCurrentWarframe].Level;
                    warframes[iCurrentWarframe].CurrentModPoints -= warframes[iCurrentWarframe].Level;
                }
                
                WarframeMPTB.Text = Convert.ToString(warframes[iCurrentWarframe].MaxModPoints);
                CurrentModPointsLabel.Text = Convert.ToString(warframes[iCurrentWarframe].CurrentModPoints);
            }
        }

        private void WeaponCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            // set current weapon and set all stats
            // TODO: NEED TO LOAD IN WEAPONS
            /*
            for(int i = 0; i < weapons.Count; ++i)
            {
                if(WeaponCB.SelectedItem.ToString() == weapons[i].Name)
                {
                    iCurrentWeapon = i;
                    break;
                }
            }
            ShowWeaponBaseStats(weapons[iCurrentWeapon]);
            */
        }

        private void WeaponLevelNUD_ValueChanged(object sender, EventArgs e)
        {
            // update weapon level
            // TODO: NEED TO LOAD IN WEAPONS
            /*
            weapons[iCurrentWeapon].Level = Convert.ToInt32(WeaponLevelNUD.Value);
            if (weapons[iCurrentWeapon].IsSuperCharged == true)
                weapons[iCurrentWeapon].MaxModPoints = Convert.ToInt32(WeaponLevelNUD.Value) * 2;
            else
                weapons[iCurrentWeapon].MaxModPoints = Convert.ToInt32(WeaponLevelNUD.Value);
            WeaponMPTB.Text = Convert.ToString(weapons[iCurrentWeapon].MaxModPoints);
            */
        }

        private void WeaponSCCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            // update weapon mod points
            // TODO: NEED TO LOAD IN WEAPONS
            /*
            if (weapons[iCurrentWeapon].IsSuperCharged != Convert.ToBoolean(WeaponSCCB.SelectedIndex))
            {
                weapons[iCurrentWeapon].IsSuperCharged = Convert.ToBoolean(WeaponSCCB.SelectedIndex);
                if (weapons[iCurrentWeapon].IsSuperCharged)
                {
                    weapons[iCurrentWeapon].MaxModPoints += weapons[iCurrentWeapon].Level;
                    WeaponMPTB.Text = Convert.ToString(weapons[iCurrentWeapon].MaxModPoints);
                }
                else
                {
                    weapons[iCurrentWeapon].MaxModPoints -= weapons[iCurrentWeapon].Level;
                    WeaponMPTB.Text = Convert.ToString(weapons[iCurrentWeapon].MaxModPoints);
                }
            }
            */
        }

        private void WarframeWeaponTab_SelectedIndexChanged(object sender, EventArgs e)
        {
            // update current mod points
            // Warframe Tab
            if (WarframeWeaponTab.SelectedIndex == 0)
            {
                // set modslot tab to warframe
                WarframeWeaponModSlotsTC.SelectedIndex = 0;
            }
            // Weapon Tab
            else
            {
                // set modslot tab to weapons
                WarframeWeaponModSlotsTC.SelectedIndex = 1;
            }
        }

        private void WarframeWeaponModSlotsTC_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Warframe Tab
            if (WarframeWeaponModSlotsTC.SelectedIndex == 0)
                // set tab to warframe
                WarframeWeaponTab.SelectedIndex = 0;
            // Weapon Tab
            else
                // set tab to weapons
                WarframeWeaponTab.SelectedIndex = 1;
        }

        private void FactionTC_SelectedIndexChanged(object sender, EventArgs e)
        {
            // show updated enemy stats
            ShowUpdatedGrineerStats(factions[0]);
            ShowUpdatedCorpusStats(factions[1]);
            ShowUpdatedInfestedStats(factions[2]);
        }

        private void GrineerTC_SelectedIndexChanged(object sender, EventArgs e)
        {
            // show updated enemy stats
            ShowUpdatedGrineerStats(factions[0]);
        }

        private void CorpusTC_SelectedIndexChanged(object sender, EventArgs e)
        {
            // show updated enemy stats
            ShowUpdatedCorpusStats(factions[1]);
        }

        private void InfestedTC_SelectedIndexChanged(object sender, EventArgs e)
        {
            // show updated enemy stats
            ShowUpdatedInfestedStats(factions[2]);
        }
    }
}
